package com.kunteng.ynhxksh.controller;

import com.kunteng.ynhxksh.service.SBGKService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created By ShiYun with IntelliJ IDEA on 2018/4/2 10:28
 *
 * @author: ShiYun
 * @Email: 515867726@qq.com
 * @Date: 2018/4/2
 * To change this template use File | Settings | File Templates.
 */
@Api(tags = "支付设备管控接口")
@RestController
@RequestMapping("/sbgk")
public class SBGKController {

    Logger logger = LoggerFactory.getLogger(SBGKController.class);

    @Autowired
    private SBGKService sbgkService;
    @Value("${jyt.getUrl}")
    private String url;

    @ApiOperation(value = "查询设备数量统计信息", notes = "返回包括已发放设备数、已激活设备数、当前在线设备数、今日有交易设备数")
    @RequestMapping(value = "/findCountSBInfo", method = RequestMethod.GET)
    public JSONObject findCountSBInfo() {
        logger.info("findCountSBInfo..");
        return sbgkService.querySBNums();
    }

    @ApiOperation(value = "一周新激活设备数趋势", notes = "返回六天前到今天的日激活设备统计数据")
    @RequestMapping(value = "/findWeekActiveSBcount", method = RequestMethod.GET)
    public JSONArray findWeekActiveSBcount() {
        logger.info("findWeekActiveSBcount..");
        return sbgkService.querySBAweekActiveQS();
    }

    @ApiOperation(value = "今日支付方式使用占比", notes = "返回今日支付方式+交易金额+占比")
    @RequestMapping(value = "/findDQJYE", method = RequestMethod.GET)
    public JSONArray findTodayZFFS() {
        logger.info("findTodayZFFS..");
        return sbgkService.queryTodayZFFS();
    }

    RestTemplate restTemplate=new RestTemplate();
//    String url ="https://jyt.kunteng.org/yunpos/";

    @ApiOperation(value = "支付设备类型占比", notes = "显示支付设备类型名称、数量、占比")
    @RequestMapping(value = "/findZFSBRate", method = RequestMethod.GET)
    public JSONObject findZFSBRate() {
        logger.info("findTodayZFFS..");
//        {"qrcode":40,"pos":13657} 台码  pos
//        System.out.println("url==="+url);
        JSONObject jsonObject=restTemplate.getForObject(url+"yunnan/payEquipment",JSONObject.class);
        return jsonObject;
    }

    @ApiOperation(value = "支付通道占比", notes = "显示支付通道名称、交易金额、占比")
    @RequestMapping(value = "/findZFTDRate", method = RequestMethod.GET)
    public JSONObject findZFTDRate() {
        logger.info("findTodayZFFS..");
//        {"fuyou":“4444.22”,"yibao":"44444.12","tonglian":"22222.33","hxyh":"23333.00","nyyh":"0"}
        JSONObject jsonObject=restTemplate.getForObject(url+"yunnan/payTongDao",JSONObject.class);

        return jsonObject;
    }

}
